package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;

	/**
	 * 焦点事件例子
	 * @author daichangxin
	 * 
	 */	
	public class FocusEventSample extends Sprite
	{
		public function FocusEventSample()
		{
			var btn:Sprite = this.createRect();
			this.addChild(btn);
			
			btn.addEventListener(FocusEvent.FOCUS_IN, focusInHandler);
			
			//去除flash的黄色焦点框
			btn.focusRect = false;
			
			//设置焦点在btn上, 这样便触发了FocusIn事件
			stage.focus = btn;
		}
		
		private function focusInHandler(e:FocusEvent):void
		{
			trace("focusIn");
			e.currentTarget.addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
		}
		
		private function focusOutHandler(e:FocusEvent):void
		{
			trace("focusOut");
			e.currentTarget.removeEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
		}
		
		/**
		 * 创建方块
		 */		
		private function createRect():Sprite
		{
			var sp:Sprite = new Sprite();
			
			sp.graphics.beginFill(0xe00000);
			sp.graphics.drawRect(0, 0, 50, 30);
			
			return sp;
		}
		
		
	}
	
}